<?php
namespace app\appoint\model;
use app\BaseModel;
use think\facade\Db;



class IndexProject extends BaseModel{
    //定义表名
    protected $name = 'lb_appoint_project';
    /**
     * @var array
     * 查询器
     */
    protected $append=[
        'record_count_text',
        'carousel_text',
        'cate_text'
    ];
    /**
     * User: chenniang
     * Date: 2019-09-28 14:47
     * @return void
     * descption:转换富文本
     */
    public function getContentAttr($value){
        return str_replace("&amp;nbsp;","",getimgs($value));
    }
    /**
     * @param $vaule
     * @param $data
     * @return int
     * 预约人数
     */
    public function getRecordCountTextAttr($vaule,$data){
        $dis[] = ['uniacid','=',$data['uniacid']];
        $dis[] = ['project_id','=',$data['id']];
        $dis[] = ['status','>',0];
        $count = Db::name('lb_appoint_record')->where($dis)->count();
        return $count;
    }
    /**
     * @param $vaule
     * @param $data
     * @return mixed
     * 获取分类
     */
    public function getCateTextAttr($vaule,$data){
        $count = Db::name('lb_appoint_classify')->where(['id'=>$data['classify_id']])->value('title');
        return $count;
    }
    /**
     * @param $vaule
     * @return mixed|string
     * 转换封面图
     */
    public function getCoverAttr($vaule){
        $cover = transImagesOne([$vaule],['cover']);
        return is_array($cover)?$cover[0]:'';
    }
    /**
     * @param $vaule
     * @param $data
     * @return mixed
     * 转换轮播图
     */
    public function getCarouselTextAttr($vaule,$data){
        $data = transImages($data,['carousel']);
        return $data['carousel'];
    }
    /**
     * @param $query
     * 查询范围
     */
    public function scopeStatus($query, $status){
        $query->where('status', '>', $status);
    }
    /**
     * @param $dis
     * @return array
     * @throws \think\exception\DbException
     * 预约服务列表
     */
    public function proList($dis){
        $data = $this->where($dis)->status(-1)->order('top desc')->paginate(10)->toArray();
        return $data;
    }
    /**
     * @param $dis
     * @return mixed
     * 预约服务详情
     */
    public function proInfo($dis){
        $data = $this->where($dis)->status(-1)->find();
        return !empty($data)?$data->toArray():$data;
    }




}